﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DAL;
using Model;

namespace BLL
{
    public class OrgService
    {
        public static List<Provinces> GetProvinces()
        {
            //return SqlSugarHelp.scope.Queryable<Provinces>()
            //                         .Mapper(it => it.cityList, it => it.cityList.First().ProvinceID)
            //                         .Mapper((a,b,c) => )
            //                         .ToList();
           return SqlSugarHelp.scope.Queryable<Provinces>()
                        //第二层 可以偷懒，用一对多 一对一 等方式 进行查询 
                        .Mapper(s => s.cityList, s => s.cityList.First().ProvinceID)
                        //第三只能自定义查询 
                        .Mapper((s, cache) => {
                            //可以断点调试 ，s.LadEntiryList 在第二层查询中已经赋过值了
                            foreach (var t in s.cityList)
                            {
                                t.organizationCityList = SqlSugarHelp.scope.Queryable<OrganizationCity>()
                                   .Where(o => o.CityName == t.city)
                                   .ToList();//给第三层赋值
                            }

                        })
                           //.Mapper((s,acche)) 可以实现第四层查询
                        .ToList();
    }

        public static int addOrg(OrganizationCity org)
        {
            return SqlSugarHelp.scope.Insertable(org).ExecuteCommand() ;
        }
    }
}
